//
//  CooperationViewController.m
//  UniversalApp
//
//  Created by 志刚杨 on 2018/3/24.
//  Copyright © 2018年 voidcat. All rights reserved.
//

#import "CooperationViewController.h"
#import "ZHPickView.h"
#define _borderColor 0xE8E8E8
#define _backColor   0xF6F6F6

@interface CooperationViewController ()<ZHPickViewDelegate>
@property (nonatomic,strong) ZHPickView *pickView;
@property (nonatomic,strong) QMUITextView *textView;
@property(nonatomic, strong) NSString *type;
@end

@implementation CooperationViewController
{
    UITextField *txtSchool;
    QMUILabel *plsSelect;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = ASLocalizedString(@"加盟合作");
    
    self.view.backgroundColor = [UIColor colorWithRGB:_backColor];
    //请选择
    UIView *selectView = [[UIView alloc] init];
    selectView.frame = CGRectMake(0, 10, SCREEN_WIDTH, 50);
    selectView.layer.borderColor = [UIColor colorWithRGB:_borderColor].CGColor;
    selectView.backgroundColor = [UIColor whiteColor];
    selectView.layer.borderWidth = 1;
    
    UITapGestureRecognizer *tapGesturRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    [selectView addGestureRecognizer:tapGesturRecognizer];
    
    QMUILabel *lab = [[QMUILabel alloc] init];
    [selectView addSubview:lab];
    lab.text = ASLocalizedString(@"请选择");
    [selectView addSubview:lab];
    [self.view addSubview:selectView];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(selectView);
        make.left.equalTo(selectView).offset(10);
    }];
    
    //请选择
    plsSelect = [[QMUILabel alloc] init];
    [selectView addSubview:plsSelect];
    plsSelect.text = ASLocalizedString(@"请选择");
    [selectView addSubview:plsSelect];
    [self.view addSubview:selectView];
    plsSelect.textColor = RGB(22, 22, 22);
    plsSelect.font = DEFAULT_FONT(15);
    [plsSelect mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(selectView);
        make.right.equalTo(selectView).offset(-16);
    }];
    
    _textView = [[QMUITextView alloc] init];
    _textView.placeholder = ASLocalizedString(@"请填写你的联系方式");
    _textView.font = DEFAULT_FONT(13);
    [self.view addSubview:_textView];
    [_textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(selectView.mas_bottom).offset(10);
        make.left.equalTo(self.view).offset(10);
        make.right.equalTo(self.view).offset(-10);
        make.height.equalTo(@160);
        
    }];
    
    
    //示例
    QMUILabel *labeg = [[QMUILabel alloc] init];
    labeg.frame = CGRectMake(0, 120, 0, 0);
    labeg.text = @"";
    [self.view addSubview:labeg];
    labeg.textAlignment = NSTextAlignmentCenter;
    [labeg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(@170);
        make.width.equalTo(self.view);
    }];
    
    
    [self addNavigationItemWithTitles:@[ASLocalizedString(@"提交   ")] isLeft:NO target:self action:@selector(save) tags:@[@1]];

}

-(void)toobarDonBtnHaveClick:(ZHPickView *)pickView resultString:(NSString *)resultString{
//    NSInteger index = [_arrlist indexOfObject:resultString];
//    //    index++;
//    _gindex = index;
//    [plsSelect setTextColor:[UIColor colorWithRGB:0x000000]];
    plsSelect.text = resultString;
    _type = resultString;
}

-(void)tapAction:(id)tap
{
    [self showList];
}

-(void)showList
{
    //筛选出举报列表
    NSMutableArray *_arrlist = [NSMutableArray array];
    [_arrlist addObject:ASLocalizedString(@"渠道推广合作")];
    [_arrlist addObject:ASLocalizedString(@"大主播注入合作")];
    [_arrlist addObject:ASLocalizedString(@"工会负责人合作")];
    [_arrlist addObject:ASLocalizedString(@"代理商合作")];
    [_arrlist addObject:ASLocalizedString(@"城市代理人合作")];
    
    //    _arrlist  = [NSArray arrayWithArray:_reportList];
    _pickView=[[ZHPickView alloc] initPickviewWithArray:_arrlist isHaveNavControler:NO];
    _pickView.delegate = self;
    [_pickView show];
}

-(void)save
{
//
    //    [HUDHelper alert:ASLocalizedString(@"您的举报我们已经收到")];
    NSString *body = _textView.text;
    if(body.length <1)
    {
        body = @"";
    }

    if(_type.length <1 || _type == nil)
    {
        [MBProgressHUD showErrorMessage:ASLocalizedString(@"请选择加盟类型")];
        return;
    }

    [[HUDHelper sharedInstance] syncLoading];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];

    [param setObject:curUser.id forKey:@"uid"];
    [param setObject:curUser.token forKey:@"token"];
    [param setObject:body forKey:@"content"];
    [param setObject:_type forKey:@"type"];
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"page_data_api" A:@"join_in"];
    //[param setObject:@"" forKey:@""];
    
    [CYNET POSTv2:url parameters:param responseCache:^(id responseObject) {
        
    } success:^(id responseObject) {
        [[HUDHelper sharedInstance] syncStopLoading];
        [HUDHelper alert:ASLocalizedString(@"提交成功")];
        [self.navigationController popViewControllerAnimated:YES];
    } failure:^(NSString *error) {
        [MBProgressHUD showTopTipMessage:error];
    } hasCache:NO];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
